# -*- coding: utf-8 -*-
'''
Created on 12-05-2013

@author: LONG HOANG GIANG
'''
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
import logging
import pyLib
import json


logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%d/%m/%Y %H:%M:%S')


def join(src, dest):
    
    if not src.endswith('/'): src += '/'
    if not dest.endswith('/'): dest += '/'
    
    inFile = src + 'data'
    outFile = dest + 'data'
    
    if not os.path.isfile(inFile) or not os.path.isfile(outFile):
        logging.error("file not exist")
        return
    
    indata = json.loads(pyLib.decryptCipher(pyLib.gz_file_get_content(inFile)))
    outdata = json.loads(pyLib.decryptCipher(pyLib.gz_file_get_content(outFile)))
    
#    for item in indata:
#        print item
#        outdata.append(item)


    print len(outdata)
    
#    os.rename(outFile, "{0}.o".format(outFile))
#    pyLib.gz_file_put_content(outFile, pyLib.encryptCipher(json.dumps(outdata)))
    
    logging.info("finished")
    

if __name__ == '__main__':
    
    
    join('/longhoanggiang/tunghoanh/cat/tien-hiep', '/longhoanggiang/tunghoanh/cat/kiem-hiep')
    
    os._exit(1)
    
    